package cu.ds.logicalsync.fytasrealm.model;

import java.util.Random;

import cu.ds.logicalsync.fytasrealm.communication.model.PeerInfo;


public class Warrior {
	
	//coding : not complete ****
	
	private String warriorName;
	private World myWorld;
	private World myCurrentWorld;
	private PositionWorld myPositionInWorld;
	//private PositionMap myPositionColorInMap;
	private WarriorState warriorState;
	private WarriorStatus warriorStatus;	//?? not complete define ??
	private int warriorLevel;
	private int warriorHp;
	private boolean warriorIsLost;
	
	// Tay add for Service
	private PeerInfo peerInfo;
		
	public Warrior(String name) {
	    this.warriorName = name;
	    this.myWorld = null;
	    this.myCurrentWorld = null;
	    setMyPositionInWorld();
	    this.warriorState = WarriorState.Idle;
	    this.warriorStatus = WarriorStatus.Owner;
	    this.warriorLevel = 0; 	// reset every time login to system.
	    this.warriorHp = 0;		// reset every time login to system.
	  }
	public String getWarriorName() {
		return warriorName;
	}
	public void setWarriorName(String warriorName) {
		this.warriorName = warriorName;
	}
	public World getMyWorld() {
		return myWorld;
	}
	public void setMyWorld(World myWorld) {
		this.myWorld = myWorld;
	}
	public World getMyCurrentWorld() {
		return myCurrentWorld;
	}
	public void setMyCurrentWorld(World myCurrentWorld) {
		this.myCurrentWorld = myCurrentWorld;
		this.myCurrentWorld.getMyPositionInMap().setPositionColor("Me", true);
	}
	public PositionWorld getMyPositionInWorld() {
		return myPositionInWorld;
	}
	public void setMyPositionInWorld(int row,int col) {
		PositionWorld pw = new PositionWorld(row, col);
		pw.setWarriorNameInWorld(this.warriorName);
		pw.setPositionOccupy(true);
		this.myPositionInWorld = pw;
	}
	public void setMyPositionInWorld() {
		randomPosition();
	}
	
	/**
	 * @return the peerInfo
	 */
	public PeerInfo getPeerInfo() {
		return peerInfo;
	}

	/**
	 * @param peerInfo
	 *            the peerInfo to set
	 */
	public void setPeerInfo(PeerInfo peerInfo) {
		this.peerInfo = peerInfo;
	}
	public void randomPosition() {
			Random generator = new Random();
			int randomRow = generator.nextInt(7);
			int randomCol = generator.nextInt(7);
			PositionWorld pw = new PositionWorld(randomRow, randomCol);
			pw.setWarriorNameInWorld(this.warriorName);
			pw.setPositionOccupy(true);
			this.myPositionInWorld = pw;
		
	}
//	public void setMyPositionColorInMap(PositionMap myPositionColorInMap) {
//		this.myPositionColorInMap = myPositionColorInMap;
//		this.myCurrentWorld.getMyPositionInMap().setPositionColor("Me", true);
//		this.myPositionColorInMap.setPositionColor("Me", true);
//	}
	public boolean isInFightMode() {
		if (this.warriorState.equals(WarriorState.Active)) {
			return true;
		}
		else {
			return false;
		}
	}
	public WarriorState getWarriorState() {
		return warriorState;
	}
	public void setWarriorState(boolean isInFightMode) {
		//check if warrior is in fighting mode
		if (isInFightMode) {
			this.warriorState = WarriorState.Active;
		}
		else {
			this.warriorState = WarriorState.Idle;
		}
	}
	public boolean isOwnerWorld() {
		if (this.warriorStatus.equals(WarriorStatus.Owner)) {
			return true;
		}
		else {
			return false;
		}
	}
	public WarriorStatus getWarriorStatus() {
		return warriorStatus;
	}
	public void setWarriorStatus() {
		if (this.myCurrentWorld == this.myWorld) {
			this.warriorStatus = WarriorStatus.Owner;
		}
		else {
			this.warriorStatus = WarriorStatus.Peer;
		}
	}
	public int getWarriorLevel() {
		return warriorLevel;
	}
	public void setWarriorLevel(int warriorLevel) {
		this.warriorLevel = warriorLevel;
	}
	public void setWarriorLevelUp() {
		this.warriorLevel = this.warriorLevel + 1;
	}
	public int getWarriorHp() {
		return warriorHp;
	}
	public void setWarriorHp(int warriorHp) {
		this.warriorHp = warriorHp;
	}
	public void setLost(boolean wLost) {
		this.warriorIsLost = wLost;
		setWarriorState(false);
		if (wLost) {
			this.myCurrentWorld.setWorldName("DZ");
			setWarriorStatus();
		}			
	}
	public boolean isLost() {
		return this.warriorIsLost;
	}

}
